<?php
/**
 * Created by PhpStorm.
 * User: KaZeline
 * Date: 15-4-24
 * Time: 下午7:22
 * 范例套票的tid 16865
 */
header("Content-type: text/html; charset=utf-8");
error_reporting(E_ERROR | E_PARSE | E_WARNING);
include("/var/www/html/new/d/common/header.html");
include_once '/var/www/html/new/com.inc.php';
//7136 数字中心
//供应商身份获取他的分销商
   //云顶、洞都、古海、土楼
    $memberID = (
        $_SESSION['memberID']==7132 || $_SESSION['memberID']==7133 || $_SESSION['memberID']==7134 ||
        $_SESSION['memberID']==7135 || $_SESSION['memberID']==7136 || $_SESSION['memberID']==7137||
        $_SESSION['memberID']==7157) ? 7136:$_SESSION['memberID'];
    $DistorsNames_f = getRetailRow($GLOBALS['le'],$memberID);
    //TODO::加载会员数据 ---By Cgp
    $memberNames = require dirname(__FILE__) . '/module/link_product/Member.cache.php';
    $dTypeName_f =  '分销商';

    $dTypeName_a =  '供应商';
    $DistorsNames_a = getDistorsRow($GLOBALS['le']);


if($_SESSION['sdtype']==2){//景区登录时 转换sid
    $sql = "select apply_did from uu_land where salerid={$_SESSION['saccount']} limit 1";
    $GLOBALS['le']->query($sql);
    $GLOBALS['le']->fetch_assoc();
    $sid=$_SESSION['memberID']==7136?'7137': $GLOBALS['le']->f('apply_did');
}else $sid = $_SESSION['sid'];
$sql = "select group_id from pft_member where id={$sid} limit 1";
$GLOBALS['le']->query($sql);
$GLOBALS['le']->fetch_assoc();
$group_id = $GLOBALS['le']->f('group_id');
if($group_id!=4)//不是云顶分组的不能查看
    exit('Access Denied');
if(!$_GET['begintime'] || !$_GET['endtime'])
    goto mark_one;
$begintime = $_GET['begintime'];
$endtime   = $_GET['endtime'];
switch ($_GET['xtimes']) {
	case '1':
    default:
		$btime1 = $begintime;
        $etime1 = $endtime;
		break;
    case '2':
        $btime2 = $begintime;
        $etime2 = $endtime;
        break;
    case '3':
        $btime3 = $begintime;
        $etime3 = $endtime;
        break;
}
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$soap = new SoapClient(null,array(
    "location" =>"http://localhost/open/openService/pft_insideMX.php",
    "uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true")
);
//订单状态
if($_GET['status']){
    foreach ($_GET['status'] as $k => $v) {
        $st = explode('|',$v);
        foreach ($st as $ke => $va) {
            $status[$va] = $va+0;
        }
    }
    foreach ($status as $k => $v) {
        $sta .= $v.'|';
    }
    $status = rtrim($sta,'|');
}else
    $_GET['status']='';
$salerid = $_SESSION['sdtype']==2 ? $_SESSION['account'] : '';

//支付状态
$_GET['paystatus'] = $_GET['paystatus']==''? $_GET['paystatus']: abs($_GET['paystatus']+0);

if($_GET['cs'])
{
    print_r($_GET['status']);
}
//$aid = (
//    $_SESSION['memberID']==7137  ||$_SESSION['memberID']==7157  || $_SESSION['memberID']==35668 ||
//    $_SESSION['memberID']==35666 ||$_SESSION['memberID']==27585 || $_SESSION['memberID']==27584 ||
//    $_SESSION['memberID']==27583 ) ?$_SESSION['memberID']:"";
//$fid = (
//        $_SESSION['memberID']==7132 || $_SESSION['memberID']==7133 || $_SESSION['memberID']==7134 ||
//        $_SESSION['memberID']==7135 || $_SESSION['memberID']==7137 || $_SESSION['memberID']==7136 ||
//        $_SESSION['memberID']==7157) ? $_SESSION['memberID']:"";

switch ($_GET['aom']) {
	case 'aid'://已卖出
        switch($_GET['aid'])
        {
            case 0:
                $x = simplexml_load_string(
                    $soap->Order_Globle_Search(
                        "$salerid",'', "", "", "", "", "$btime1", "$etime1", "$btime2", "$etime2",
                        "$btime3", "$etime3", "", "", "", "$status", "{$_GET['paystatus']}", "", "", "",
                        0, 9999, 0, 0, "", 0, "", 0, "", "",
                        $sid, 0, 0, 0, ""),
                        'SimpleXMLElement',LIBXML_COMPACT
                );
                break;
            default:
                $x = simplexml_load_string(
                    $soap->Order_Globle_Search(
                        "$salerid",$_GET['aid']+0, "", "", "", "", "$btime1", "$etime1", "$btime2", "$etime2",
                        "$btime3", "$etime3", "", "", "", "$status", "{$_GET['paystatus']}", "", "", "",
                        0, 9999, 0, 0, "", 0, "", 0, "", "",
                        $sid, 0, 0, 0, ""),
                    'SimpleXMLElement',LIBXML_COMPACT
                );
                break;
        }
        break;
	default://已买到的
        switch($_GET['fid'])
        {
            case 0:
                $x = simplexml_load_string(
                    $soap->Order_Globle_Search(
                        "$salerid","$sid", "", "", "", "", "$btime1", "$etime1", "$btime2", "$etime2",
                        "$btime3", "$etime3", "", "", "", "$status", "{$_GET['paystatus']}", "", "", "",
                        0, 9999, 0, 0, "", 0, "", 0, "", "",
                        '', 0, 0, 0, ""),
                    'SimpleXMLElement',LIBXML_COMPACT
                );
                break;
            default:
                $x = simplexml_load_string(
                    $soap->Order_Globle_Search(
                        "$salerid","$sid", "", "", "", "", "$btime1", "$etime1", "$btime2", "$etime2",
                        "$btime3", "$etime3", "", "", "", "$status", "{$_GET['paystatus']}", "", "", "",
                        0, 9999, 0, 0, "", 0, "", 0, "", "",
                        $_GET['fid']+0, 0, 0, 0, ""),
                    'SimpleXMLElement',LIBXML_COMPACT
                );
                break;
        }
       /*
        $x = simplexml_load_string(
            $soap->Order_Globle_Search(
                "","", "", "", "", "", "", "", "", "",
                "", "", "1040300", "", "", "", "", "", "", "",
                0, 9999, 0, 0, "", 0, "", 0, "", "",
                '', 0, 0, 0, ""),
            'SimpleXMLElement',LIBXML_COMPACT
        );
        */
		break;
}
if($_GET['csj']==1){
    echo '<pre>';
    print_r($x);
    echo '</pre>';
}
$entime=microtime(true);
/**
 * 景区要可以看到明细的报表 包含套票的各种子票的
 * 查到的订单 不是指定类型的都continue
 * 最后再去结算查到的所以套票的子票数量
 * 观光车和索道的价格都是按供货价来算
 * 酒店的价格 就按套票减去观光车和索道和景区门票的价格
 */
$ticket_data = include_once '/var/www/html/new/d/module/zax/yd_report/ticket_data.php';
$no_price = array(//过期的现付产品 取不到零售价 将之前的产品写在这里
    23788=>15800,
);
$tmp = $aid =array();
foreach ($x->Rec as $k => $v) {
    //只统计以下特定票类
    if((string)$v->UUp_type!='F' && //套票
        (string)$v->UUp_type!='G' && //餐厅
        !((string)$v->UUp_type=='C' && (int)$v->UUpack_order==0) && //酒店单票
        (int)$v->UUlid!=5102/*云顶景区直通车*/
    )
        continue;
    //如果是酒店 查询下是否是套票里的子票 套票里的酒店不用显示
    if((int)$v->UUordernum==2864744){
        $v->UUpmode =1;
        $x->Rec[$k]->UUpmode =1;
    }
    $mid = mid($v);
    /**
     * 支付方式的区别
     */
    switch ((int)$v->UUpmode) {
    	case 4://现场支付 用零售价
            local:
            $type = 'local';
            if($no_price[(int)$v->UUtid]){//过期的现付产品 取定死的价钱
                $tmp[(int)$v->UUtid][$mid]['local']['tmoney'] += (int)$v->UUtnum * $no_price[(int)$v->UUtid];
                break;
            }
            $tmp[(int)$v->UUtid][$mid]['local']['tmoney'] += (int)$v->UUtnum * $ticket_data[(int)$v->UUtid]['data_2']['lsj'];
    		break;
        case 2://授信支付
            $type = 'credit';
            $uutprice = second_hand($v);
            $tmp[(int)$v->UUtid][$mid]['credit']['tmoney'] += (int)$v->UUtnum * $uutprice;
            break;
        case 1://支付宝在线支付
            $type = 'online';
            $uutprice = second_hand($v);
            $tmp[(int)$v->UUtid][$mid]['online']['tmoney'] += (int)$v->UUtnum * $uutprice;
    		break;
        case 3://自供自销
            if($ticket_data[(int)$v->UUtid]['pay']=='local')//在线支付
                goto local;
            else{
                $type = 'self';
                $tmp[(int)$v->UUtid][$mid]['self']['tmoney'] += (int)$v->UUtnum *(int)$v->UUtprice;
            }
            break;
    }
    $tmp[(int)$v->UUtid][$mid][$type]['title'] = (string)$v->UUltitle;
    $tmp[(int)$v->UUtid][$mid][$type]['dname'] = $mid;
    $tmp[(int)$v->UUtid][$mid][$type]['tnum'] += 1;
    $tnum   += 1;
    $tmp[(int)$v->UUtid][$mid][$type]['ti_num'] += (int)$v->UUtnum;
    $tmp[(int)$v->UUtid][$mid][$type]['p_type'] = (string)$v->UUp_type;
}
foreach ($tmp as $k => $v){
//    echo '<pre>';
//    print_r($tmp);
//    echo '</pre>';
    foreach ($v as $ke => $va){
        foreach ($va as $key => $val) {
            if ($val['p_type']!='F') goto mark_two;//原先做的关于套票的处理 先包一层 现在要新加酒店和直通车
            //j就是景(jing)点 c就是观光车(che) s就是索(suo)道 h就是hotel
            if($sid==7132 || $sid==7133 || $sid==7134 || $sid==7135 ){//是 云顶景区 且是 套票 时 多输出一行子票内的明细需要用到子票的名称
                $tmp[$k][$ke][$key]['jname'] = $ticket_data[$k]['data'][0]['title'];
                $tmp[$k][$ke][$key]['cname'] = $ticket_data[$k]['data'][1]['title'];
                if($ticket_data[$k]['data'][2])//套票含索道类型时
                    $tmp[$k][$ke][$key]['sname'] = $ticket_data[$k]['data'][2]['title'];
                if($ticket_data[$k]['data'][3])//套票含酒店类型时
                    $tmp[$k][$ke][$key]['hname'] = $ticket_data[$k]['data'][3]['title'];
            }
            switch ($key){//现场支付取零售价 其他类型取分销价
                case 'local':
                    $data = 'data_2';
                    break;
                default:
                    $data = 'data';
                    break;
            }
            $tmp[$k][$ke][$key]['jti_num'] =
                $val['ti_num'] * $ticket_data[$k][$data][0]['num'];
            $tmp[$k][$ke][$key]['cti_num'] =
                $val['ti_num'] * $ticket_data[$k][$data][1]['num'];
            $tmp[$k][$ke][$key]['cmoney'] =
                $tmp[$k][$ke][$key]['cti_num'] * $ticket_data[$k][$data][1]['price'];
            $tmp[$k][$ke][$key]['sti_num'] =
                $val['ti_num'] * $ticket_data[$k][$data][2]['num'];
            $tmp[$k][$ke][$key]['smoney'] =
                $tmp[$k][$ke][$key]['sti_num'] * $ticket_data[$k][$data][2]['price'];

            if($ticket_data[$k][$data][3]){//套票内有酒店时 景点取固定价钱 酒店的价钱是总价钱减去别的产品的价钱
                $tmp[$k][$ke][$key]['jmoney'] =
                    $tmp[$k][$ke][$key]['jti_num'] * $ticket_data[$k][$data][0]['price'];
                $tmp[$k][$ke][$key]['hti_num'] =
                    $val['ti_num'] * $ticket_data[$k][$data][3]['num'];
                $tmp[$k][$ke][$key]['hmoney'] =
                    $val['tmoney'] - $tmp[$k][$ke][$key]['jmoney'] -
                    $tmp[$k][$ke][$key]['cmoney'] - $tmp[$k][$ke][$key]['smoney'];
            }else{//没有酒店时 景点价钱是总价减去观光车和索道
                $tmp[$k][$ke][$key]['jmoney'] =$val['tmoney'] -
                    $tmp[$k][$ke][$key]['cmoney'] - $tmp[$k][$ke][$key]['smoney'];
            }
            mark_two:
            if ($val['p_type']=='C')//酒店类单品的处理
            {
                $tmp[$k][$ke][$key]['hmoney'] = $val['tmoney'];
            }
        }
    }

}
//处理转分销价格 把整个订单传进来 返回值是int 价格
function second_hand($order){
    $prices = (string)$order->UUaids_price;
    if($prices==0)
        return (int)$order->UUtprice;
    $prices = explode(',',$prices);
    $aid = (string)$order->UUaids;
    $aid = explode(',',$aid);
    $s = array_search($_SESSION['sid'],$aid);
    switch ($_GET['aom']) {
        case 'aid'://最后一级供应商看到的价格直接就是订单的价格
            return $prices[$s] ? $prices[$s] : (int)$order->UUtprice;
            break;

        default://最后一级分销商商看到的价格直接就是订单的价格
            return $_SESSION['sid'] != (int)$order->UUmid ?
                        $prices[$s-1] : (int)$order->UUtprice;
            break;
    }

}
// 云顶获取供应商
function getDistorsRow($le,$format=1,$real=false){
    $ida=array();
    $ids='';
    $memberID= (
        $_SESSION['memberID']==27583 || $_SESSION['memberID']==27584 ||  $_SESSION['memberID']==35666 ||
        $_SESSION['memberID']==35668 || $_SESSION['memberID']==27583 ||  $_SESSION['memberID']==7136 ||
        $_SESSION['memberID']==7137  || $_SESSION['memberID']==7157) ? 7136:$_SESSION['memberID'];
    $memObject = new \pft\Member\MemberAccount($le, $memberID);
    $sql="SELECT r.parent_id FROM pft_member_relationship r left join  pft_member m on m.id=r.parent_id WHERE r.parent_id!={$memberID} and r.son_id=$memberID AND r.ship_type=0 AND m.group_id=4 and m.status=0";
    $GLOBALS['le']->query($sql);
    $myDistors=array();
    while($row=$GLOBALS['le']->fetch_assoc()){
        if( $_SESSION['memberID']==27583 || $_SESSION['memberID']==27584 ||  $_SESSION['memberID']==35666 ||
            $_SESSION['memberID']==35668 || $_SESSION['memberID']==27583 ) continue;
        $myDistors[]=$row['parent_id'];
    }

    //加上自己的
    $myDistors[]=$memberID;
    if(!$format)return $myDistors;
    if(count($myDistors)>0)  $DistorsNames = $memObject->getMemName($myDistors,$real);
    return $DistorsNames;
}
// 云顶获取分销商
function getRetailRow($le,$memberID=0,$format=1){
    if($memberID==0){
        $memberID= ($_SESSION['dtype']==6) ? $_SESSION['sid']:$_SESSION['memberID'];
    }
    $memObject = new \pft\Member\MemberAccount($le,$memberID);
    // 获取曾经建立过的，防止销售后再解除
    $sql="SELECT r.son_id FROM pft_member_relationship r LEFT JOIN pft_member m ON m.id=r.son_id WHERE r.son_id!={$memberID} and r.parent_id=$memberID AND r.ship_type=0  and m.status=0".$GLOBALS['mobile_account'];
    $GLOBALS['le']->query($sql);
    $myDistors=array();
    while($row=$GLOBALS['le']->fetch_assoc()){
        if( $_SESSION['memberID']==27583 || $_SESSION['memberID']==27584 ||  $_SESSION['memberID']==35666 ||
            $_SESSION['memberID']==35668 || $_SESSION['memberID']==27583 ) continue;
        $myDistors[]=$row['son_id'];
    }
    //加上自己的（自供应）
    if($_SERVER['SCRIPT_URL']!='/orderReport.html'&& $memberID==$_SESSION['memberID'] && $memberID!=7136)//出售中的产品报表不应该出现自己
        $myDistors[]=$memberID;
    if(!$format)	return $myDistors;
    if(count($myDistors)>0) {
        $DistorsNames = $memObject->getMemName($myDistors);
    }
    return $DistorsNames;
}
//取销售渠道 永远是 云顶官网->数字中心->再下面的这个人 如果没有 就是订单的购买者
function mid($order){
    $aids = (string)$order->UUaids;
    $aid = explode(',',$aids);
    if(!$aid[2]){
        $GLOBALS['aid'][(int)$order->UUmid]=(int)$order->UUmid;
        return (int)$order->UUmid;
    }
    $GLOBALS['aid'][$aid[2]]=$aid[2];
    return $aid[2];
}

foreach ($GLOBALS['aid'] as $k => $v) {
    $mids .= $v.',';
}
$mids = trim($mids,',');
//print_r($aid);
//echo $mids;
//exit;
if($mids){
    $sql = "select id,dname from pft_member where id in ($mids)";
    $GLOBALS['le']->query($sql);
    $row = array();
    while($row=$GLOBALS['le']->fetch_assoc()){
        $dname[$row['id']] = $row['dname'];
    }
}

mark_one:
function pmode($type){
    switch ($type) {
        case 'local':
            echo '现场支付';
            break;
        case 'credit':
            echo '<span style="color:green">授信支付</span>';
            break;
        case 'online':
            echo '<span style="color:red">在线支付</span>';
            break;
        case 'self':
            echo '<span style="color:purple">自供自销</span>';
            break;
    }
}
?>
<link rel="stylesheet" type="text/css" href="//www.12301.cc/shops/css/gmem.css"/>

<script language="javascript" src="//www.12301.cc/js/WdatePicker.js"></script>
<script src="//www.12301.cc/js/jsorder.js"></script>
<script type="text/javascript">
    var tableToExcel = (function() {
        var uri = 'data:application/vnd.ms-excel;base64,'
            , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
            , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
            , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
        return function(table, name) {
            if (!table.nodeType) table = document.getElementById(table)
            var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
            window.location.href = uri + base64(format(template, ctx))
        }
    })()
    $("#txtStartTime").bind("click focus", function () {

        var endtimeTf = $dp.$('txtEndTime');
        WdatePicker({
            maxDate: '#F{$dp.$D(\'txtEndTime\')}',
            dateFmt: "yyyy-MM-dd",
            onpicked: function () { endtimeTf.focus(); }
        });
    });
    $("#txtEndTime").bind("click focus", function () {
        WdatePicker({
            minDate: '#F{$dp.$D(\'txtStartTime\')}',
            dateFmt: "yyyy-MM-dd"
        });
    });
</script>
<link rel="stylesheet" type="text/css" href="//www.12301.cc/css/order_member.css"/>
<style>
    .report{overflow: hidden;margin:10px 0; padding:15px; border:1px solid #eee; }
    .report span.part{ margin-right:20px;}
    input.time{    background: url("../images/rili.png") no-repeat scroll right center #FFFFFF;
        border: 1px solid #7F9DB9;
        height: 20px;
        line-height: 20px;
        width: 120px;}
    .total{ width:100%; text-align:center;}
    input.checkbox{ vertical-align:-2px; margin-right:2px;}
    .btn{ background:#eee; padding:4px 15px; *padding:4px 8px; background:url("../images/mc_title.png") no-repeat right top; color:#fff; border:none; cursor:pointer}
    #excel{margin-left:10px;}
    .red {color:red}
    .rank {width:1000px;margin:0 auto 10px;}
    #begintime,#endtime{width: 150px}
</style>
<div class="mem_right">
    <form action="" method="get"  name="form" >
        <div class="mem_time">
             <span class="part">
                <label>
                    <!--交易日期：-->
                    <select name="xtimes" id="time_type">
                        <option value="1" <?=$_REQUEST['xtimes']==1?'selected' :''?>>下单时间</option>
                        <option value="2" <?=$_REQUEST['xtimes']==2?'selected' :''?>>预计游玩</option>
                        <option value="3" <?=$_REQUEST['xtimes']==3?'selected' :''?>>完成时间</option>
                    </select>
                </label>
                    <input type="text" name="begintime" id="begintime" class="time" value="<?=$begintime?>" onFocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
                    <label>至</label>
                    <input type="text" name="endtime" id="endtime" class="time" value="<?=$endtime?>" onFocus="WdatePicker({startDate:'%y-%M-01 23:59:59',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
            </span>
            <span  class="part">
		<input class="checkbox" type="checkbox" name="status[]" <?=in_array("0|1|2|3|5|6|7",$_GET['status'])?"checked ":""?> value="0|1|2|3|5|6|7"/><label>全部</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=in_array("0|6",$_GET['status'])?"checked":""?> value="0|6"/><label>未使用</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=(in_array("1|7",$_GET['status']) )?"checked":""?> value="1|7"/><label>已使用</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=(in_array("2",$_GET['status']))?"checked":""?> value="2"/><label>已过期</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=(in_array("3|5",$_GET['status']))?"checked":""?> value="3|5"/><label>已取消</label>
	</span>
<br><br>

    支付情况:<select name="paystatus" >
                <option value="">全部</option>
                <option value="1" <?=$_GET['paystatus']=='1'?' selected="selected"':''?>>已支付</option>
                <option value="2" <?=$_GET['paystatus']=='2'?' selected="selected"':''?>>未支付</option>
                <option value="0" <?=$_GET['paystatus']=='0'?' selected="selected"':''?>>景区到付</option>
            </select>
    查询类型:<select name="aom" id="amid">
                <option value="mid" >已买到报表</option>
                <option value="aid" <?=$_GET['aom']=='aid'?' selected="selected"':''?>>已卖出报表</option>
            </select>
            <?if((isset($DistorsNames_f) && count($DistorsNames_f)>0)||(isset($DistorsNames_a) && count($DistorsNames_a)>0)):?>
            <span  class="part_f" style="display: <?echo ($_GET['aom']=='mid'||!$_GET['aom'])? 'inline':'none';?>">
            <?=$dTypeName_a?>：<?=GetHtmlSelect($DistorsNames_a, 'fid',$_GET['fid'], array('k'=>0,'v'=>'--供应商--'))?>
            </span>
            <span  class="part_a" style="display:<?echo $_GET['aom']=='aid'?'inline':'none'?>">
            <?=$dTypeName_f?>：<?=GetHtmlSelect($DistorsNames_f, 'aid',$_GET['aid'], array('k'=>0,'v'=>'--分销商--'))?>
            </span>
            <?endif;?>
            <input type="submit" value="提交">
            <input type="button" onclick="tableToExcel('testTable', 'W3C Example Table')" value="导出到Excel">
        </div>
    </form>
</div>
</div>
<div class="rank">
    <div class="rankcon">
        <table class="ranktab" id='testTable'>
            <thead id="rankhd">
                <th>序号</th>
                <th class="tL">景区名称</th>
                <th class="tL">销售渠道</th>
                <th><span class="sort" onclick="sortTable('offmain',3, true ,this);">订单总数</span></th>
                <th><span class="sort" onclick="sortTable('offmain',4, true ,this);">门票总数</span></th>
                <th><span class="sort" onclick="sortTable('offmain',5, true ,this);">总金额</span></th>
                <th><span class="sort" onclick="sortTable('offmain',6, true ,this);">景点门票金额</span></th>
                <th><span class="sort" onclick="sortTable('offmain',7, true ,this);">观光车金额</span></th>
                <th><span class="sort" onclick="sortTable('offmain',8, true ,this);">索道金额</span></th>
                <th><span class="sort" onclick="sortTable('offmain',9, true ,this);">酒店金额</span></th>
                <th class="tL">备注</th>
                <th>支付方式</th>
            </thead>
        <tbody id="offmain">
        <?php
        if(count($tmp)):
        $m = 0;
        foreach ($tmp as $k => $v) {
            foreach ($v as $ke => $va){
                foreach ($va as $key => $val) {
                    if($val['title']=='') continue;
                    $ti_num +=$val['ti_num'];
                    $jmoney +=$val['jmoney'];
                    $tmoney +=$val['tmoney'];
                    $cmoney +=$val['cmoney'];
                    $smoney +=$val['smoney'];
                    $hmoney +=$val['hmoney'];
        ?>
        <tr data-id="">
            <td><?=++$m?></td>
            <td><?=$val['title']?></td>
            <td><?=$dname[$val['dname']]?></td>
            <td><?=$val['tnum']?></td>
            <td><?=$val['ti_num']?></td>
            <td><?=$val['tmoney']/100?></td>
            <td><?=$val['jmoney']/100?></td>
            <td><?=$val['cmoney']/100?></td>
            <td><?=$val['smoney']/100?></td>
            <td><?=$val['hmoney']/100?></td>
            <td class="tL"></td>
            <td><?=pmode($key)?></td>
        </tr>
        <?if(($sid==7132 || $sid==7133 || $sid==7134 || $sid==7135 ) && $val['p_type']=='F'){
        /*
         * 是云顶景区的话每总套票循环时多三层tr
         * 第一层景点
         * 第二层观光车
         * 第三层索道
         * 第四层酒店
         */
        ?>
        <tr data-id="jd">
            <td><?=++$m?></td>
            <td><?=$val['jname']?></td>
            <td><?=$dname[$val['dname']]?></td>
            <td><?=$val['tnum']?></td>
            <td><?=$val['jti_num']?></td>
            <td><?=$val['jmoney']/100?></td>
            <td><?=$val['jmoney']/100?></td>
            <td><?=0?></td>
            <td><?=0?></td>
            <td><?=0?></td>
            <td class="tL"></td>
            <td><?=pmode($key)?></td>
            <?php
            $tnum   +=$val['tnum'];
            $ti_num +=$val['jti_num'];
            $tmoney +=$val['jmoney'];
            $jmoney +=$val['jmoney'];?>
        </tr>
        <tr data-id="ggc">
            <td><?=++$m?></td>
            <td><?=$val['cname']?></td>
            <td><?=$dname[$val['dname']]?></td>
            <td><?=$val['tnum']?></td>
            <td><?=$val['cti_num']?></td>
            <td><?=$val['cmoney']/100?></td>
            <td><?=0?></td>
            <td><?=$val['cmoney']/100?></td>
            <td><?=0?></td>
            <td><?=0?></td>
            <td class="tL"></td>
            <?php
            $tnum   +=$val['tnum'];
            $ti_num +=$val['cti_num'];
            $tmoney +=$val['cmoney'];
            $cmoney +=$val['cmoney'];?>
            <td><?=pmode($key)?></td>
        </tr>
        <?if($ticket_data[$k]['data'][2]){?>
        <tr data-id="sd">
            <td><?=++$m?></td>
            <td><?=$val['sname']?></td>
            <td><?=$dname[$val['dname']]?></td>
            <td><?=$val['tnum']?></td>
            <td><?=$val['sti_num']?></td>
            <td><?=$val['smoney']/100?></td>
            <td><?=0?></td>
            <td><?=0?></td>
            <td><?=$val['smoney']/100?></td>
            <td><?=0?></td>
            <td class="tL"></td>
            <?php
            $tnum   +=$val['tnum'];
            $ti_num +=$val['sti_num'];
            $tmoney +=$val['smoney'];
            $smoney +=$val['smoney'];;?>
            <td><?=pmode($key)?></td>
        </tr>
        <?}?>
        <?if($ticket_data[$k]['data'][3]){?>
        <tr data-id="hotel">
            <td><?=++$m?></td>
            <td><?=$val['hname']?></td>
            <td><?=$dname[$val['dname']]?></td>
            <td><?=$val['tnum']?></td>
            <td><?=$val['hti_num']?></td>
            <td><?=$val['hmoney']/100?></td>
            <td><?=0?></td>
            <td><?=0?></td>
            <td><?=0?></td>
            <td><?=$val['hmoney']/100?></td>
            <td class="tL"></td>
            <?php
            $tnum   +=$val['tnum'];
            $ti_num +=$val['hti_num'];
            $tmoney +=$val['hmoney'];
            $hmoney +=$val['hmoney'];?>
            <td><?=pmode($key)?></td>
        </tr>
        <?}}?>
        <?}}}//三个foreach的循环后半部分的括号?>
        <tr> <td>合价：</td><td></td><td></td><td><?=$tnum?></td><td><?=$ti_num?></td><td><?=$tmoney/100?><td><?=$jmoney/100?></td><td><?=$cmoney/100?></td><td><?=$smoney/100?></td><td><?=$hmoney/100?></td></tr>
        </tbody>
        <tfoot>
        <?php else:?>
            <tr>
                <td align="left" colspan="9">&nbsp;&nbsp;&nbsp;交易日期无销售订单！</td>
            </tr>
        <?php endif;?>
        </tfoot>
    </table>
</div>
</div>
<script>
    $("#txtStartTime").bind("click focus", function () {

        var endtimeTf = $dp.$('txtEndTime');
        WdatePicker({
            maxDate: '#F{$dp.$D(\'txtEndTime\')}',
            dateFmt: "yyyy-MM-dd",
            onpicked: function () { endtimeTf.focus(); }
        });
    });
    $("#txtEndTime").bind("click focus", function () {
        WdatePicker({
            minDate: '#F{$dp.$D(\'txtStartTime\')}',
            dateFmt: "yyyy-MM-dd"
        });
    });
</script>

<script language="javascript" src="http://www.12301.cc/module/wxh/js/yd_report.js"></script>
<?
include 'common/footer.html';
?>